package com.glamour.hlcity.common.exception;

import com.glamour.hlcity.common.enums.ErrorCodeEnum;

public class BizException extends RuntimeException {

	private static final long serialVersionUID = 55328307072675579L;
	/**
	 * 错误码前置
	 */
	private static final String DEFAULT_MESSAGE_PREFIX = "Error Code : ";
	
	/**
	 * 错误码
	 */
	private ErrorCodeEnum errorCodeEnum;

	public BizException(ErrorCodeEnum errCode, String message, Throwable cause) {
		super(DEFAULT_MESSAGE_PREFIX + errCode.getCode() + "["
				+ errCode.getMessage() + "]" + message, cause);
		this.errorCodeEnum = errCode;
	}
	
	public BizException(ErrorCodeEnum errCode, Throwable cause) {
		super(DEFAULT_MESSAGE_PREFIX + errCode.getCode() + "["
				+ errCode.getMessage() + "]" , cause);
		this.errorCodeEnum = errCode;
	}
	
	public BizException(String message, Throwable cause) {
		super(DEFAULT_MESSAGE_PREFIX +message , cause);
	}
	
	public BizException(ErrorCodeEnum errCode) {
		super(DEFAULT_MESSAGE_PREFIX +errCode.getCode());
		this.errorCodeEnum = errCode;
	}
	public BizException(ErrorCodeEnum errCode,String message) {
		super(DEFAULT_MESSAGE_PREFIX + errCode.getCode() + "["
				+ errCode.getMessage() + "]" );
		this.errorCodeEnum = errCode;
	}
	
	
	
	/**
	 * 获得错误码
	 * @return
	 */
	public String getErrorCode(){
		if(errorCodeEnum==null){
			return ErrorCodeEnum.DATA_ILLE.getCode();
		}
		return errorCodeEnum.getCode();
	}
}
